package com.bawei.cms.web.controllers;

import com.bawei.cms.domain.Article;
import com.bawei.cms.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("portal")
public class PortalController {

    @Resource
    private ArticleService articleService;

    @RequestMapping("/index")
    public String index(Model model, Article article,
                        @RequestParam(defaultValue = "1")int pageNum,
                        @RequestParam(defaultValue = "4")int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Article> list = articleService.list(article);
        PageInfo<Article> pageInfo = new PageInfo<>(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("article",article);
        return "index";
    }
}
